/**
 * 
 */
package es.ats.codington.festival.services;

import java.io.IOException;
import java.sql.Connection;
import java.util.ArrayList;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import es.ats.codington.festival.daos.DAOManager;
import es.ats.codington.festival.daos.EventDAOImpl;
import es.ats.codington.festival.daos.PlaceDAOImpl;
import es.ats.codington.festival.domain.Place;

import es.ats.codington.festival.interfaces.daos.iPlaceDAOImpl;
import es.ats.codington.festival.interfaces.daos.iVisitorDAO;
import es.ats.codington.festival.interfaces.services.iCreatePlace;
import es.ats.codington.festival.interfaces.services.iViewPlace;
import es.ats.codington.festival.utils.FERSDataConnection.FersDC;


/**
 * The Class PlaceService.
 *
 * @author JAVA101_01
 */
public class PlaceService implements iViewPlace, iCreatePlace {

		/** The place dao. */
		private iPlaceDAOImpl placeDAO;
	
			/**
			 * Instantiates a new place service.
			 */
			public PlaceService(){
					ApplicationContext ctx = new ClassPathXmlApplicationContext(  "beans.xml");  
					DAOManager daoManager = (DAOManager) ctx.getBean("daoManager");
					this.placeDAO = daoManager.getPlaceDAO();
		
			}
	
	
	/* (non-Javadoc)
	 * @see es.ats.codington.festival.interfaces.services.iViewPlace#viewPlace(int)
	 */
	@Override
	public Place viewPlace(int idplace) throws Exception {
		Place place2 = null;
		
		place2=placeDAO.viewPlace(idplace);
			return place2;
	}

	/**
	 * Gets the ids place.
	 *
	 * @param type the type
	 * @return the ids place
	 * @throws Exception the exception
	 */
	public ArrayList<Integer> getIdsPlace(String type) throws Exception {
		
		ArrayList<Integer> idsPlaceByType= new ArrayList<Integer>();
		idsPlaceByType=placeDAO.getIdsPlace(type);
		
				
			return idsPlaceByType;
			
		}
	
	/* (non-Javadoc)
	 * @see es.ats.codington.festival.interfaces.services.iCreatePlace#createPlace(es.ats.codington.festival.domain.Place)
	 */
	@Override
	
	public boolean createPlace(Place place) throws Exception {

		boolean reg=false;
		
		try{
			
			reg=placeDAO.createPlace(place);
			
			}catch (Exception ex){
				System.out.println("Error Exception con mensaje: " + ex.getMessage());
			}

			
		return reg;
		
	}
}
